<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var minimumOperations = function (nums, start, goal) {
      let q = [[start, 0]];
      let set = new Set();
      set.add(start);
      while (q.length > 0) {
        let [c, s] = q.shift();
        for (let i of nums) {
          let cr = [c + i, c - i, c ^ i];
          for (let j of cr) {
            if (j === goal) return s + 1;
            else if (j > 1000 || j < 0) continue;
            else if (!set.has(j)) {
              set.add(j);
              q.push([j, s + 1]);
            }
          }
        }
      }
      return -1;
    };
    console.log(minimumOperations([2, 4, 12], 2, 12));
  </script>
</body>

</html>